package cn.dreamsoul.dogprofile


import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout

@Preview
@Composable
fun ConstrantLayoutDemo() {
    Card(
        elevation = CardDefaults.cardElevation(
            defaultElevation = 6.dp
        ),
        modifier = Modifier
            .fillMaxSize()
            .padding(top = 100.dp, end = 16.dp, bottom = 100.dp, start = 16.dp)
            .border(width = 2.dp, color = Color.White, shape = RoundedCornerShape(8.dp))
    ) {
        ConstraintLayout(modifier = Modifier.fillMaxSize()) {
            val (image, nameText) = createRefs()
            Image(
                painter = painterResource(id = R.drawable.cheems7),
                contentDescription = "cheems's avatar",
                modifier = Modifier
                    .size(100.dp)
//                裁剪至圆形
                    .clip(CircleShape)
//                注意，border是基于容器的，因此我们需要设置shape为Circle
                    .border(width = 2.dp, color = Color.Red, shape = CircleShape)
                    .constrainAs(image) {
                        top.linkTo(parent.top, margin = 30.dp, goneMargin = 30.dp)
                        start.linkTo(parent.start)
                    },
//            默认是缩放到至少有一条边占满容器（默认为Fit）
//            下面修改为裁剪
                contentScale = ContentScale.Crop
            )
            Text(modifier = Modifier.constrainAs(nameText) {
                top.linkTo(image.bottom)
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            }, text =  "I'm cheems.")
        }
    }
}

@Composable
fun PStats(count: String, title: String) {
    Column(horizontalAlignment = Alignment.CenterHorizontally) {
        Text(count, fontWeight = FontWeight.Bold)
        Text(title)
    }
}